<?php
class UserServiceForm extends Zend_Form{
	public function __construct($options = null)
	{
		parent::__construct($options);
		$this->addPrefixPath('Vmg_Form_Decorator', 'Vmg/Form/Decorator', 'decorator');

		// load translator
		$registry = Zend_Registry::getInstance();
		$translate = $registry->get('Zend_Translate');
		$access_levels = $registry->get('access_level_config');

		// set up form
		$this->setName('agentservice');
		$this->setAttrib('id', 'agentserviceForm');

		$service_id = new Zend_Form_Element_Select ('serviceIdAgentServiceForm');
		$service_id->setLabel($translate->_("Service name"))
		->setRequired(true)
		->addFilter('StripTags')
		->addFilter('StringTrim')
		->setDecorators(array("Composite"))
		;

		$services = new Service();
		$rows = $services->fetchAll();
		foreach($rows as $row){
			$service_id->addMultiOption($row->id, $row->code);
		}

		$agent_id = new Zend_Form_Element_Select('agentIdAgentServiceForm');
		$agent_id->setLabel($translate->_("Agent"))
		->setRequired(true)
		->addFilter('StripTags')
		->addFilter('StringTrim')
		->setDecorators(array("Composite"))
		;

		$users = new Users();
		$select = $select = $users->getAdapter()->select()
								->from(array('u' => 'vmg_user'), array('u.id as agent_id', 'u.name as agent_name'))
					            ->joinleft(array('t' => 'vmg_user_type'),
					                        'u.type_id = t.id', array('type_name'))
					            ->where('t.access_level = ' . $access_levels->mobishop_level);
		$rows = $users->getAdapter()->fetchAll($select);
		foreach($rows as $row){
			$agent_id->addMultiOption($row['agent_id'], $row['agent_name'] . ' - ' . $translate->_($row['type_name']));
		}

		$agent_code = new Zend_Form_Element_Text('agentCodeAgentServiceForm');
		$agent_code->setLabel($translate->_("Agent code"))
		->setRequired(true)
		->addFilter('StripTags')
		->addFilter('StringTrim')
		->setAttrib('size', 20)
		->setDecorators(array("Composite"))
		;

		$submit = new Zend_Form_Element_Submit('submitAgentServiceForm');
		$submit->setAttrib('id', 'submitAgentServiceForm');
		$submit->setLabel('')
				->setValue($translate->_('Add'))
				->setDecorators(array("Composite"));

		$back = new Zend_Form_Element_Button('backAgentServiceForm');
		$back->setValue($translate->_('Back'));
		$back->setLabel('');
		$back->setAttrib('onclick', 'javascript: history.go(-1);');
		$back->setDecorators(array('Composite'));

		$this->addElements(array($service_id, $agent_id, $agent_code, $submit, $back));
	}
}
?>